const router = require('express').Router();
const mongoose = require('mongoose');
const DictionaryModel = mongoose.models['Dictionary'];

router.get('/get', async function (req, res, next) {
    try{
        let data=await DictionaryModel.findOne({key:req.query.key});
        res.data(data.value);
    }catch(e){
        next(e.message);
    }
});

router.get('/getJSON', async function (req, res, next) {
    try{
        let data=await DictionaryModel.findOne({key:req.query.key});
        res.data(JSON.parse(data.value));
    }catch(e){
        next(e.message);
    }
});

router.get('/getProvince', async function (req, res, next) {
    try{
        let data=await DictionaryModel.findOne({key:req.query.key});
        res.data(data.toVantJson());
    }catch(e){
        next(e.message);
    }
});

module.exports = router;